home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / AppleShare API / PowerPC AppleShare API / PPC SyncServerDispatch / SyncServerDispatch.c < prev   
Encoding:
C/C++ Source or Header  |  1995-04-12  |  4.3 KB  |  139 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Glue to call ServerDispatch from a PowerPC application
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support
  7. **
  8. **    File:        SyncServerDispatch.c
  9. **
  10. **    Copyright © 1995 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #include <Types.h>
  23. #include <MixedMode.h>
  24. #include <Errors.h>
  25. #include <Traps.h>
  26.  
  27. #include "ServerControlIntf.h"
  28.  
  29. /*
  30. **    The function calling convention ServerDispatchProc
  31. */
  32. typedef    pascal OSErr (*ServerDispatchProcPtr)(long dZero, SCParamBlockPtr thePB);
  33.  
  34. typedef UniversalProcPtr ServerDispatchProcUPP;
  35.  
  36. /*
  37. **    Procedure information for ServerDispatchProc function
  38. */
  39. enum
  40. {
  41.     uppServerDispatchProcInfo = kRegisterBased
  42.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(long)))
  43.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterD0, SIZE_CODE(sizeof(long)))
  44.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA0, SIZE_CODE(sizeof(SCParamBlockPtr)))
  45. };
  46.  
  47. /*
  48. **    The CallServerDispatchProc macro calls ServerDispatch
  49. **    using uppServerDispatchProcInfo defined above.
  50. **
  51. **    Notes:
  52. **        ServerDispatch expects register D0 to always be 0 on input, so the
  53. **        dZero parameter (the first parameter) is always 0.
  54. **
  55. **        Not all versions of Macintosh File Sharing return a result in
  56. **        register D0, so we don't bother to get the value in D0. Instead, the
  57. **        SyncServerDispatch glue code (below) returns the result from the
  58. **        parameter block's ioResult field.
  59. */
  60. #define CallServerDispatchProc(userRoutine, thePB)        \
  61.         CallOSTrapUniversalProc((UniversalProcPtr)(userRoutine), uppServerDispatchProcInfo, ServerDispatch, 0, (thePB))
  62.  
  63. /*****************************************************************************/
  64.  
  65. /*
  66. **    A concise version of TrapAvailable function.
  67. **    (another effort in the quest for smaller, faster code)
  68. */
  69. static    Boolean    TrapAvailable(short theTrap)
  70. {
  71.     TrapType tType;
  72.     short     numToolboxTraps;
  73.     
  74.     /* Get the trap type */
  75.     if ( (theTrap & 0x0800) > 0 )
  76.         tType = ToolTrap;
  77.     else
  78.         tType = OSTrap;
  79.     
  80.     /* If theTrap is ToolTrap, see if it is in the trap table */
  81.     if ( tType == ToolTrap )
  82.     {
  83.         /* Get the number of toolbox traps */
  84.         if ( NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap) )
  85.             numToolboxTraps = 0x200;
  86.         else
  87.             numToolboxTraps = 0x400;
  88.         
  89.         /* Is theTrap in the trap table? */
  90.         if ( (theTrap & 0x07ff) >= numToolboxTraps )
  91.             theTrap = _Unimplemented;    /* No, make it _Unimplemented */
  92.     }
  93.     
  94.     /* Trap is available if it doesn't equal _Unimplemented */
  95.     return ( NGetTrapAddress(theTrap, tType) != NGetTrapAddress(_Unimplemented, ToolTrap) );
  96. }
  97.  
  98. /*****************************************************************************/
  99.  
  100. /*
  101. **    SyncServerDispatch is the glue code to call the ServerDispatch trap
  102. **    from PowerPC code.
  103. */
  104. pascal OSErr SyncServerDispatch(SCParamBlockPtr PBPtr)
  105. {
  106.     /*
  107.     **    Keep the address of ServerDispatch in a static so we don't
  108.     **    have to check for ServerDispatch and get its address
  109.     **    every time SyncServerDispatch is called.
  110.     */
  111.     static ServerDispatchProcUPP serverDispatchAddress = NULL;
  112.     
  113.     /* If serverDispatchAddress is uninitialized, try to initialize it */
  114.     if ( serverDispatchAddress == NULL )
  115.     {
  116.         /* Make sure ServerDispatch is available (just in case someone didn't check for it first) */
  117.         if ( TrapAvailable(ServerDispatch) )
  118.         {
  119.             /* Get the address of ServerDispatch */
  120.             serverDispatchAddress = (ServerDispatchProcUPP)NGetTrapAddress(ServerDispatch, OSTrap);
  121.         }
  122.     }
  123.     
  124.     /* If serverDispatchAddress was initialized */ 
  125.     if ( serverDispatchAddress != NULL )
  126.     {
  127.         /* Call ServerDispatch and return the result from ioResult */
  128.         (void) CallServerDispatchProc(serverDispatchAddress, PBPtr);
  129.         return ( PBPtr->startPB.ioResult );
  130.     }
  131.     else
  132.     {
  133.         /* Return an error to indicate ServerDispatch wasn't available */
  134.         return ( paramErr );
  135.     }
  136. }
  137.  
  138. /*****************************************************************************/
  139.